package com.cykj.pos.controller.api;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.cykj.pos.domain.SynchronizationDataDTO;
import com.cykj.pos.service.IBizMerchantInfoService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/new/info" )
public class PosHybController {
    private final IBizMerchantInfoService bizMerchantInfoService ;
    private final PosV1TransactioNotice posV2TransactioNotice;
    @PostMapping("/addInfo")
    public String addInfo(@RequestBody String params){
        System.out.println("会员宝入网接口"+params);
        Map map=new HashMap();
        JSONObject obj=JSON.parseObject(params);
        bizMerchantInfoService.hybAddInfo(obj);
        map.put("status","success");
        return JSON.toJSONString(map);
    }
    @PostMapping("/transDetail")
    public String transDetail(@RequestBody String params){
        System.out.println("会员宝交易接口"+params);
        Map map=new HashMap();
        JSONObject obj=JSON.parseObject(params);
        List<SynchronizationDataDTO> list= posV2TransactioNotice.changeTrading(obj);
        for(SynchronizationDataDTO vo:list){
            posV2TransactioNotice.transact(vo);
        }
        map.put("status","success");
        return JSON.toJSONString(map);
    }
}
